package com.wanlong.sys.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanlong.sys.dao.SysPrivilegeMapper;
import com.wanlong.sys.model.SysPrivilege;
import com.wanlong.sys.service.ISysPrivilegeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 万龙
 * @name
 * @project_name wanlong
 * @package_name com.wanlong.sys.service.impl
 * @description
 * @date 2019/2/25
 */
@Service
public class SysPrivilegeService implements ISysPrivilegeService {
    @Autowired
    private SysPrivilegeMapper sysPrivilegeMapper;

    public long insert(SysPrivilege sysPrivilege) {
        sysPrivilegeMapper.insertSelective(sysPrivilege);
        return sysPrivilege.getId();
    }

    public int update(SysPrivilege sysPrivilege) {
        return sysPrivilegeMapper.update(sysPrivilege);
    }

    public int delete(SysPrivilege sysPrivilege) {
        return sysPrivilegeMapper.delete(sysPrivilege);
    }

    public PageInfo<SysPrivilege> getPageSysPrivilegeListByName(String name, Integer pageNo, Integer pageSize) {
        pageNo = pageNo == null?1:pageNo;
        pageSize = pageSize == null?10:pageSize;
        PageHelper.startPage(pageNo, pageSize);
        List<SysPrivilege> list = sysPrivilegeMapper.getSysPrivilegeList(name);
        //用PageInfo对结果进行包装
        PageInfo<SysPrivilege> page = new PageInfo<SysPrivilege>(list);

        return page;
    }
}
